//
//  YHYMViewViewController.m
//  Home
//
//  Created by 杨泓晔 on 16/4/12.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "YHYMViewViewController.h"
#import "WSMineCell.h"
#import "WSMineHeaderView.h"
#import "WSMineFooterView.h"
#import "SheeViewController.h"
#import "VippViewController.h"
#import "VipViewController.h"
#import "SupeiViewController.h"
#import "YHYDesignerPersonViewController.h"//我的主页 个人信息
#import "qianViewController.h" //充值
#import "YHYDesigneViewsViewController.h"
#import "YHYEditHomePageViewController.h"//添加任务
#import "WUPriveViewController.h"
#import "WUMMyShowCaseViewController.h"
#import "WUConnectViewController.h" //沟通过的人物
#import "WUStoreViewController.h"  //收藏过的任务
#import "WUShareSheet.h"//分享
#import "UIImage+BlurScreenImage.h"
#import "UIView+Screen.h"


@interface YHYMViewViewController ()<UITableViewDataSource,UITableViewDelegate,WSMineFooterViewDelegate,WSMineHeaderViewDelegate,WUShareSheetDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) WSMineHeaderView *headView;
@property (nonatomic,strong) NSArray *titleArr;

@end

@implementation YHYMViewViewController

- (void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBar"] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    //self.navigationController.navigationBarHidden = YES;
    
}

- (void)viewWillDisappear:(BOOL)animated {
    
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _titleArr=[NSArray arrayWithObjects:@"我的主页",@"我的钱包", nil];
    
    self.view.backgroundColor = LV;
    
    //分享
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigation_share@2p"] style:UIBarButtonItemStylePlain target:self action:@selector(shareAction)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    
    //设置
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigation_shezhi@2p"] style:UIBarButtonItemStylePlain target:self action:@selector(setAction)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];

    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49) style:UITableViewStylePlain];
    self.tableView.backgroundColor = LV;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 50 * AUTO_HEIGHT;
    self.tableView.showsVerticalScrollIndicator = NO;
    //去掉线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
   // self.tableView.backgroundColor = LV;
    [self.view addSubview:_tableView];
    [self.tableView registerClass:[WSMineCell class] forCellReuseIdentifier:@"cell"];
    
    //头视图
    self.headView = [[WSMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 360 * AUTO_HEIGHT)];
    self.headView.delegate = self;
    self.tableView.tableHeaderView = self.headView;
    
    
    WSMineFooterView *footView = [[WSMineFooterView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 260 * AUTO_WIDTH)];
    footView.delegate = self;
    self.tableView.tableFooterView = footView;

    

}
#pragma mark -- tableView delegate && dataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 8 * AUTO_HEIGHT;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    WSMineCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.titleStr = _titleArr[indexPath.section];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    WSMineCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.selected = NO;
   
    
    if (indexPath.section == 0) {
        WUPriveViewController *edit=[[WUPriveViewController alloc]init];
        edit.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:edit animated:YES];
    }else{
    
        qianViewController *qian=[[qianViewController alloc]init];
        [self.navigationController pushViewController:qian animated:YES];
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    [self.headView updateHeaderView:scrollView.contentOffset];
}

#pragma mark -- headerView代理方法
- (void)pushDetailViewController:(NSInteger)type {
    
    
    switch (type) {
        case MINEHEADERSELECTWORK:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"1"]) {
                
                WUMMyShowCaseViewController *edit=[[WUMMyShowCaseViewController alloc]init];
                edit.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:edit animated:YES];
            }
            break;
            
        case MINEHEADERSELECTTALKED:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"1"]) {
             
                WUConnectViewController  *connect=[[WUConnectViewController alloc]init];
                connect.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:connect animated:YES];
            }
            
            break;
        case MINEHEADERSELECTCOLLECTED:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"1"]) {
               
                WUStoreViewController  *store=[[WUStoreViewController alloc]init];
                store.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:store animated:YES];
                
            }
           
            break;
            
        case MINEHEADERSELECTHEADER:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"2"]) {
                
            } else {
                YHYDesigneViewsViewController  *Designe=[[YHYDesigneViewsViewController alloc]init];
                Designe.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:Designe animated:YES];
                
            }
            break;
            
        case MINEHEADERSELECTSCORE:
        {
            VippViewController *vipp=[[VippViewController alloc]init];
            vipp.hidesBottomBarWhenPushed=YES;
            [self.navigationController pushViewController:vipp animated:YES];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark -- footerView代理方法
- (void)footerPushViewController:(NSInteger)type {
    
    if (type == 1200) {
        
        VippViewController *vitality=[[VippViewController alloc]init];
        vitality.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vitality animated:YES];
    } else if (type == 1201) {
        
        SupeiViewController *supei=[[SupeiViewController alloc]init];
        supei.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:supei animated:YES];
    } else {
        
        VipViewController *vipView=[[VipViewController alloc]init];
        vipView.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vipView animated:YES];
    }
}


-(void) setAction
{
    SheeViewController *chong=[[SheeViewController alloc]init];
    [self.navigationController pushViewController:chong animated:YES];
}


-(void) shareAction
{
    WUShareSheet *sheet=[[WUShareSheet alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    sheet.delegate=self;
    sheet.backImageVi.image=[[self.view convertViewToImage]applyBlurWithRadius:10.0 tintColor:[UIColor colorWithWhite:1 alpha:0.4] saturationDeltaFactor:1.8 maskImage:nil];
}


-(void) shareButtonClick:(NSInteger)index
{
    if (index ==0) {
        
        NSLog(@"微信微信微信");
        
    }else if (index ==1){
        
        NSLog(@"微博微博微博");
        
    }else if (index ==2){
        NSLog(@"朋友圈朋友圈朋友圈");
    }else{
        NSLog(@"短信短信短信");
    }
}

@end
